/*****************************************************
Copyright (C) 2020. All rights reserved.
File name     ：TestMain.c
Version       ：v1.0
Author        ：zhengqijun
Date          ：2020-04-17
Function List ：
Description   ：main function
******************************************************/

#include <stdio.h>  // for printf
#include "Graph.h"

#define MaxVertexSize (6)

// PrintGraph for testing
static void PrintGraph(Graph G);

void PrintGraph(Graph G) {
    int i;

    for (i = 0; i < N(G); ++i) {
        printf("%d|%c -> ", i, Vertex(i, G));
        ArcList L = First(i, G);
        while (L != NULL) {
            printf("%d[%d] -> ", Index(L, G), ArcWeight(L, G));
            L = Next(L, G);
        }
        printf("^\n");
    }
}

// main function
int main(void) {
    Graph G;
    int i;

    G = Initialize();

    if (N(G) == 0) {
        printf("Graph is empty!\n");
    } else {
        printf("Graph is not empty!\n");
    }

    printf("Insert vertex of graph: [ ");
    for (i = 0; i < MaxVertexSize; ++i) {
        printf("%c ", 'A' + i);
        InsertVertex('A' + i, G);
    }
    printf("]\n");

    printf("Insert arcs of graph:\n");
    {
        printf("%c -> %c[%d]\n", 'A', 'B', 3);
        InsertArc('A', 'B', 3, G);
        printf("%c -> %c[%d]\n", 'A', 'C', 1);
        InsertArc('A', 'C', 1, G);
        printf("%c -> %c[%d]\n", 'B', 'C', 2);
        InsertArc('B', 'C', 2, G);
        printf("%c -> %c[%d]\n", 'B', 'D', 4);
        InsertArc('B', 'D', 4, G);
        printf("%c -> %c[%d]\n", 'C', 'E', 1);
        InsertArc('C', 'E', 1, G);
        printf("%c -> %c[%d]\n", 'C', 'F', 5);
        InsertArc('C', 'F', 5, G);
        printf("%c -> %c[%d]\n", 'E', 'F', 1);
        InsertArc('E', 'F', 1, G);
    }

    if (N(G) == 0) {
        printf("Graph is empty!\n");
    } else {
        printf("Graph is not empty!\n");
    }

    printf("Print graph:\n");
    PrintGraph(G);
    printf("\n");

    printf("Remove vertex D in graph\n");
    RemoveVertex('D', G);

    printf("Print graph:\n");
    PrintGraph(G);
    printf("\n");

    printf("Remove arc C->E in graph\n");
    RemoveArc('C', 'E', G);

    printf("Print graph:\n");
    PrintGraph(G);
    printf("\n");

    Destroy(G);

    return 0;
}

// EOF

